package com.meilai.project.constant;

import com.meilai.project.dto.base.SimpleObj;
import lombok.Getter;

import java.util.List;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.stream.Collectors;

/**
 * @description 制作单-配送类型
 * @author 张驰
 * @date 2022/8/16 10:38
 */
@Getter
public enum AdMakeDeliverTypeEnum {
    SUPPLIER(1, "供应商配送", 2, false),
    OWN(2, "自提", 3, false),
    RUN(3, "跑腿", 4, false),
    PHOTO(4, "制作后拍照拍视频", 1, true);

    private final Integer id;
    private final String name;
    private final Integer sort;
    private final Boolean sample; // 是否小样配送独有

    AdMakeDeliverTypeEnum(Integer id, String name, Integer sort, Boolean sample) {
        this.id = id;
        this.name = name;
        this.sort = sort;
        this.sample = sample;
    }

    /**
     * 后去配送方式
     * @param sample 是否小样配送
     */
    public static List<SimpleObj> getList(boolean sample){
        SortedMap<Integer, AdMakeDeliverTypeEnum> map = new TreeMap<Integer, AdMakeDeliverTypeEnum>();
        for (AdMakeDeliverTypeEnum adMakeDeliverTypeEnum : AdMakeDeliverTypeEnum.values()) {
            if(sample || !adMakeDeliverTypeEnum.getSample()) map.put(adMakeDeliverTypeEnum.getSort(), adMakeDeliverTypeEnum);
        }
        return map.values().stream().map(d -> new SimpleObj(d.getId().longValue(), d.getName())).collect(Collectors.toList());
    }

    public static AdMakeDeliverTypeEnum getEnumById(Integer id) {
        for (AdMakeDeliverTypeEnum adMakeDeliverTypeEnum : AdMakeDeliverTypeEnum.values()) {
            if (adMakeDeliverTypeEnum.getId().equals(id)) {
                return adMakeDeliverTypeEnum;
            }
        }
        return null;
    }
}
